<?php
/*------------------------------------------------------------------------
# mod_rizvn_support - Module RizVN Support
# ------------------------------------------------------------------------
# Author: Phuoc Nguyen
# copyright Copyright (C) 2011 RizVN.Net. All Rights Reserved.
# @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
# Websites: http://www.rizvn.net
# Technical Support: Mail - rizvn93@gmail.com
-------------------------------------------------------------------------*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );


class modRizVNSupport_Yahoo
{


function rizvn_yahoo_status($yahoo_user){ 

//Format text etc and set up variables

$yahoo_status_render ='';

//add directory path
$yahoo_pngs = 'modules/mod_rizvn_support/images/yahoo/';

//add full path to images
$yahoo_pngs_directory = JURI::base().$yahoo_pngs;

//Use cURL to grab either 00 (Offline) or 01 (Online)

if (function_exists('curl_init')) {


        $cUrl = curl_init(); 
        curl_setopt($cUrl, CURLOPT_URL, 'http://opi.yahoo.com/online?u='.$yahoo_user.'&m=a&t=1');
	  	curl_setopt($cUrl, CURLOPT_HEADER, false); 
        curl_setopt($cUrl, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($cUrl, CURLOPT_TIMEOUT, 10); 

        $yahoo_status_code = trim(curl_exec($cUrl)); 
        curl_close($cUrl); 
 
		$yahoo_status_code = intval($yahoo_status_code); 
		//For error testing
		//echo $yahoo_status_code;
        
        //Dependant on the code returned - we change the image displayed

               if ($yahoo_status_code =='00'){ 
			$yahoo_status_render = $yahoo_status_render.'<a href="ymsgr:sendIM?'.$yahoo_user.'"><img border=0 src="'.$yahoo_pngs_directory.'offline.png"></a>';
			}

                if ($yahoo_status_code =='01'){ 
                        $yahoo_status_render = $yahoo_status_render.'<a href="ymsgr:sendIM?'.$yahoo_user.'"><img border=0 src="'.$yahoo_pngs_directory.'online.png"></a>'; 
			}
//add the text after the image if it is required



//end the div and return the result
$yahoo_status_render = $yahoo_status_render.'';
     

return $yahoo_status_render;

} else {

$yahoo_status_render = "You do not have the cURL library installed - Contact your Hosting Company";
return $yahoo_status_render;
}

} 

//End of Class
}

class modRizVNSupport_GTalk
{

	
// http://www.justin-cook.com/wp/2006/03/31/php-parse-a-string-between-two-strings/

	function Waz_Message($string, $start, $end)
{
	$string = " ".$string;
	$ini = strpos($string,$start);
	if ($ini == 0) return "";
	$ini += strlen($start);
	$len = strpos($string,$end,$ini) - $ini;
	return substr($string,$ini,$len);
}

function rizvn_gtalk_status($gtalk_badge){ 

//Add google js

$doc = &JFactory::getDocument();
$doc->addScript('http://www.google.com/talk/service/js/1302663308-badge-js.js');

//Format text etc and set up variables

$gtalk_status_render ='';

//add directory paths
$gtalk_pngs = 'modules/mod_rizvn_support/images/gtalk/';

//add full path to images and text files
$gtalk_pngs_directory = JURI::base().$gtalk_pngs;


//Use cURL to get gtalk server to point to one of our images - then fiddle it!

if (function_exists('curl_init')) {


        $cUrl = curl_init(); 
      	curl_setopt($cUrl, CURLOPT_URL, 'http://www.google.com/talk/service/badge/Show?tk='.$gtalk_badge.'');
		curl_setopt($cUrl, CURLOPT_HEADER, 0); 
        	curl_setopt($cUrl, CURLOPT_RETURNTRANSFER, 1); 
        	curl_setopt($cUrl, CURLOPT_TIMEOUT, 10); 

      $gtalk_status_code = curl_exec($cUrl);
	
        curl_close($cUrl);

		//For error testing
		//$gtalk_status_render = $gtalk_status_render.'Full Code : '.$gtalk_status_code.'<br/>Any Use?<br/>';
        
        //Strip off the bits we do not need


	//Now find out if we are online - busy or offline and display the image

if (strpos($gtalk_status_code,"online.gif")) { 
$gtalk_status_render = $gtalk_status_render.'<a href="http://www.google.com/talk/service/badge/Start?tk='.$gtalk_badge.'" target=_blank><img src="'.$gtalk_pngs_directory.'online.png" border=0></a>';
}


elseif (strpos($gtalk_status_code,"busy.gif")) { 
$gtalk_status_render = $gtalk_status_render.'<img border=0 src="'.$gtalk_pngs_directory.'busy.png">';  
}

elseif (strpos($gtalk_status_code,"idle.gif")) { 
$gtalk_status_render = $gtalk_status_render.'<img border=0 src="'.$gtalk_pngs_directory.'idle.png">';  
}

else { 
$gtalk_status_render = $gtalk_status_render.'<img border=0 src="'.$gtalk_pngs_directory.'offline.png">';  
}

//end the div and return the result
$gtalk_status_render = $gtalk_status_render.'';
     

return $gtalk_status_render;

} else {

$gtalk_status_render = 'You do not have the cURL library installed - Contact your Hosting Company';
return $gtalk_status_render;
}

} 

//End of Class
}

class modRizVNSupport_Skype
{



function rizvn_skype($skype_account,$skype_pngs,$skype_choice){ 

$skype_render ='';

//add directory path
$skype_pngs = 'modules/mod_rizvn_support/images/skype/'.$skype_pngs;

//add trailing /
$skype_pngs = $skype_pngs.'/';

//add full path to images
$skype_pngs_directory = JURI::base().$skype_pngs;

        
//Get the info from Skype website - you need cURL installed for this to work
//Version 1.0.1 Add check for whether cURL exists
//Version 1.1.1 Added support for hyphens in usernames and stopped cURL caching problems

if (function_exists('curl_init')) {

        $cUrl = curl_init();
//Encode the account name as utf8 - gets over problems of having hypens
// or dashes in usernames - thanks to essexboyupnorth for this
$skype_account = utf8_encode($skype_account); 

	//Also need to Get the response as a text file - not HTML
	curl_setopt($cUrl, CURLOPT_TRANSFERTEXT, 1);

 	// An attempt to allow multiple uses of the module
	// Do Not Use A Cached Version 
	// Problem here seems to be Joomlas Caching
	// But at least this seems to sort out the unknown error problem :)
	// Thanks to Christian from Baden-Baden :)
	
	curl_setopt($cUrl, CURLOPT_FORBID_REUSE, 1); 
	curl_setopt($cUrl, CURLOPT_FRESH_CONNECT, 1);

	//Clear out any DNS Stuff asap
	//Useful if you have more than one instance of the module online
	//Though It does not seem to work too well!

 	curl_setopt($cUrl, CURLOPT_DNS_CACHE_TIMEOUT, 0);

	  curl_setopt($cUrl, CURLOPT_URL,'http://mystatus.skype.com/'.$skype_account.'.num'); 
        curl_setopt($cUrl, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($cUrl, CURLOPT_TIMEOUT, 5); 
	 
        $status_code = trim(curl_exec($cUrl)); 
        curl_close($cUrl); 

        $status_code = intval($status_code); 
		//For error testing
		//$skype_render = $skype_render.' user id here ' .$skype_account;
	
        
        //Dependant on the code returned - we change the image displayed

               
                if ($status_code =='1'){ 
                        $skype_render = $skype_render.'<img src="'.$skype_pngs_directory.'offline.png" alt="'.$skype_choice.' '.$skype_account.'" /></a>';			}
 
                if ($status_code =='2'){ 
                        $skype_render = $skype_render.'<a href="skype:'.$skype_account.'?'.$skype_choice.'"><img src="'.$skype_pngs_directory.'online.png" alt="'.$skype_choice.' '.$skype_account.'" /></a>';			}

                if ($status_code =='3'){ 
                          $skype_render = $skype_render.'<a href="skype:'.$skype_account.'?'.$skype_choice.'"><img src="'.$skype_pngs_directory.'away.png" alt="'.$skype_choice.' '.$skype_account.'" /></a>';			}
 
                if ($status_code =='4'){ 
                          $skype_render = $skype_render.'<a href="skype:'.$skype_account.'?'.$skype_choice.'"><img src="'.$skype_pngs_directory.'not_available.png" alt="'.$skype_choice.' '.$skype_account.'" /></a>';
			}
 
                if ($status_code =='5'){ 
                          $skype_render = $skype_render.'<a href="skype:'.$skype_account.'?'.$skype_choice.'"><img src="'.$skype_pngs_directory.'do_not_disturb.png" alt="'.$skype_choice.' '.$skype_account.'" /></a>';
			}
 
                if ($status_code =='6'){ 
                          $skype_render = $skype_render.'<a href="skype:'.$skype_account.'?'.$skype_choice.'"><img src="'.$skype_pngs_directory.'invisible.png" alt="'.$skype_choice.' '.$skype_account.'" /></a>';			} 
                
		    if ($status_code =='7'){ 
                          $skype_render = $skype_render.'<a href="skype:'.$skype_account.'?'.$skype_choice.'"><img src="'.$skype_pngs_directory.'skype_me.png" alt="call '.$skype_account.'" /></a>';			}

//end the div and return the result
$skype_render = $skype_render.'';
return $skype_render;

} else {

$skype_render = "You do not have the cURL library installed - Contact your Hosting Company";
return $skype_render;
}

} 

//End of Class
}

class modRizVNSupport_AIM
{

function rizvn_aim_status($aim_username){ 

//Format text etc and set up variables

$aim_status_render ='';

//add directory paths
$aim_pngs = 'modules/mod_rizvn_support/images/aim/';

//add full path to images and text files
$aim_pngs_directory = JURI::base().$aim_pngs;


//Use cURL to get AIM server to point to one of our images - then fiddle it!

if (function_exists('curl_init')) {


        $cUrl = curl_init(); 
      	curl_setopt($cUrl, CURLOPT_URL, 'http://big.oscar.aol.com/'.$aim_username.'?on_url='.$aim_pngs_directory.'online.png&off_url='.$aim_pngs_directory.'offline.png');
		curl_setopt($cUrl, CURLOPT_HEADER, 1); 
        	curl_setopt($cUrl, CURLOPT_RETURNTRANSFER, 1); 
        	curl_setopt($cUrl, CURLOPT_TIMEOUT, 10); 

      $aim_status_code = curl_exec($cUrl);
	//grabbing the Header to check that we are redirecting to online or offline image
	$aim_status_online = "online.png";
        curl_close($cUrl);

		//For error testing
		//$aim_status_render = $aim_status_render.'<br/>Header string - '.$aim_status_code;
        
        //Dependant on the code returned - we change the image displayed
	//Bit different from other cURL scripts I used b4

	$pos_aim = strpos($aim_status_code,$aim_status_online);

		if($pos_aim === false) { 
            	$aim_status_render = $aim_status_render.'<img border=0 src="'.$aim_pngs_directory.'offline.png">'; 
        } 

	else  { 
             $aim_status_render = $aim_status_render.'<a href="aim:goim?screenname='.$aim_username.'"><img border=0 src="'.$aim_pngs_directory.'online.png"></a>'; 
        }

//end the div and return the result
$aim_status_render = $aim_status_render.'';
     

return $aim_status_render;

} else {

$aim_status_render = "You do not have the cURL library installed - Contact your Hosting Company";
return $aim_status_render;
}

} 

//End of Class
}

?> 